/*
 * Author: Sanjay Giri
 * 
 * 
 *   CHIP8 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   CHIP8 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with CHIP8.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


public class KeyPad {

	
	public static boolean[] keypad = new boolean[16];
	
	
	public boolean isKeyPressed(int i){
		
		return keypad[i];
		
	}
	
	
	
	public int isAnyKeyPressed(){
		
		for(int i=0;i<16;i++){
			
			if(keypad[i] == true){
				return i;
			}
			
		}
		
		return -1;
		
	}
	
	
	public void press(char i){
		
		if(i == '1'){
			keypad[0] = true;
		}
		else if(i == '2'){
			keypad[1] = true;
		}
		else if(i == '3'){
			keypad[2] = true;
		}
		else if(i == '4'){
			keypad[3] = true;
		}
		if(i == 'q'){
			keypad[4] = true;
		}
		else if(i == 'w'){
			keypad[5] = true;
		}
		else if(i == 'e'){
			keypad[6] = true;
		}
		else if(i == 'r'){
			keypad[7] = true;
		}
		else if(i == 'a'){
			keypad[8] = true;
		}
		else if(i == 's'){
			keypad[9] = true;
		}
		else if(i == 'd'){
			keypad[10] = true;
		}
		else if(i == 'f'){
			keypad[11] = true;
		}
		else if(i == 'z'){
			keypad[12] = true;
		}
		else if(i == 'x'){
			keypad[13] = true;
		}
		else if(i == 'c'){
			keypad[14] = true;
		}
		else if(i == 'v'){
			keypad[15] = true;
		}
		
	}
	
	public void release(char i){
		
		if(i == '1'){
			keypad[0] = false;
		}
		else if(i == '2'){
			keypad[1] = false;
		}
		else if(i == '3'){
			keypad[2] = false;
		}
		else if(i == '4'){
			keypad[3] = false;
		}
		if(i == 'q'){
			keypad[4] = false;
		}
		else if(i == 'w'){
			keypad[5] = false;
		}
		else if(i == 'e'){
			keypad[6] = false;
		}
		else if(i == 'r'){
			keypad[7] = false;
		}
		else if(i == 'a'){
			keypad[8] = false;
		}
		else if(i == 's'){
			keypad[9] = false;
		}
		else if(i == 'd'){
			keypad[10] = false;
		}
		else if(i == 'f'){
			keypad[11] = false;
		}
		else if(i == 'z'){
			keypad[12] = false;
		}
		else if(i == 'x'){
			keypad[13] = false;
		}
		else if(i == 'c'){
			keypad[14] = false;
		}
		else if(i == 'v'){
			keypad[15] = false;
		}
		
		
	}
	
}
